//
// Created by wangwanlong on 2024/6/17.
//

#ifndef MCGPP_CONNECTIVITY_SET_H
#define MCGPP_CONNECTIVITY_SET_H
#include "typedef.h"
#include "macros.h"
namespace mcgpp{
  //边的连接集，使用位运算实习
  //好像可以使用bitset代替实现

  class ConnectivitySet{
  public:
    ConnectivitySet() = default;
    ~ConnectivitySet() = default;

    void add(PartitionID p_id){
      _bit |= 1<<p_id;
      ++_size;
    }
    bool contains(const PartitionID p_id) const {
      return (_bit >> p_id) & 1;
    }
    void remove(PartitionID p_id){
      --_size;
      if(_size == 0 || _bit == 3){
        _bit ^= 1 << p_id;
      }
    }
    int size() {
      return _size;
    }
    int bit(){
      return _bit;
    }

    void clear(){
      _size = 0;
      _bit = 0;
    }



    int _size = 0;
    unsigned int _bit;
  };
}
#endif //MCGPP_CONNECTIVITY_SET_H
